package com.example.dbdesign.service.impl;

import com.example.dbdesign.service.FilePathService;
import org.springframework.stereotype.Service;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Service
public class FilePathServiceImpl implements FilePathService {
    @Override
    public Boolean save(MultipartFile file, String path) {
//        String path2 = path + fileName + System.currentTimeMillis();
        File targetFile = new File(path);
        if (!targetFile.getParentFile().exists()) {
            targetFile.getParentFile().mkdirs();
        }
        try{
            FileCopyUtils.copy(file.getBytes(), targetFile);
            return true;
        } catch(IOException e){
            e.printStackTrace();
        }
        return false;
    }
}
